const { func } = require("joi")
let basic = [
    // 全局系统参数
    {
        label: 'sysInfo',
        name: '全局系统参数',
        value: []
    },
    // 设备类型
    {
        label: 'deviceType',
        name: '设备类型',
        value: [{
            value: '1',
            name: '设备类型1',
            id: 1,
        }, {
            value: '2',
            name: '设备类型2',
            id: 2,
        }, {
            value: '0',
            name: '设备类型3',
            id: 3,
        }, {
            value: '0',
            name: '设备类型4',
            id: 4,
        }, ]
    },
    // 计量单位
    {
        label: 'unitNo',
        name: '计量单位',
        value: [{
            value: '1',
            name: 'ng/L',
            id: 1,
        }, {
            value: '2',
            name: 'ng/dL',
            id: 2,
        }, {
            value: '0',
            name: 'ng/mL',
            id: 3,
        }, {
            value: '0',
            name: 'μg/L',
            id: 4,
        }, ]
    },
    // 类别名称
    {
        label: 'className',
        name: '类别名称',
        value: [{
            value: '1',
            name: '糖尿病与代谢类',
            id: 1,
        }, {
            value: '2',
            name: '甲状腺功能类',
            id: 2,
        }, {
            value: '0',
            name: '肿瘤标志物类',
            id: 3,
        }, {
            value: '0',
            name: '性腺激素类',
            id: 4,
        }, ]
    },
    // 故障等级
    {
        label: 'grade',
        name: '故障等级',
        value: [{
            value: '1',
            name: '严重',
            id: 1,
        }, {
            value: '2',
            name: '一般',
            id: 2,
        }, {
            value: '3',
            name: '比较严重',
            id: 3,
        }, {
            value: '4',
            name: '可以忽略',
            id: 4,
        }, ]
    },
    // 设备状态
    {
        label: 'deviceState',
        name: '设备状态',
        value: [{
                value: '0',
                name: '在线',
                id: 0,
            },
            {
                value: '1',
                name: '离线',
                id: 1,
            },
            {
                value: '2',
                name: '异常',
                id: 2,
            },
            {
                value: '3',
                name: '维修中',
                id: 3,
            },
            {
                value: '4',
                name: '报修中',
                id: 4,
            },
        ]
    },
    // 性别菜单
    {
        label: 'generMenu',
        name: '性别菜单',
        value: [{
            value: 1,
            name: '男性',
            id: 1,
        }, {
            value: 2,
            name: '女性',
            id: 2,
        }, {
            value: 9,
            name: '未知性别',
            id: 9,
        }]
    },
    // 任务状态
    {
        label: 'taskStatus',
        name: '任务状态',
        value: [{
                value: 0,
                name: '未开始',
                id: 0,
            },
            {
                value: 1,
                name: '处理中',
                id: 1,
            },
            {
                value: 2,
                name: '已完成',
                id: 2,
            },
            {
                value: 3,
                name: '异常',
                id: 3,
            },
        ]
    },
]

module.exports = [
    // queryBasic
    {
        url: '/vue-admin-template/basic/getDict',
        type: 'post',
        response: config => {
            let data = config.body.data
            if (data && data.label) {
                for (let index = 0; index < basic.length; index++) {
                    if (data.label == basic[index].label) {
                        return {
                            code: 20000,
                            data: basic[index]
                        }
                    }


                }

            } else {
                return {
                    code: 20000,
                    data: basic
                }
            }


        }
    },
    // insertBasic
    {
        url: '/vue-admin-template/basic/insertDict',
        type: 'post',
        response: config => {
            let data = config.body
            for (let i = 0; i < basic.length; i++) {
                if (basic[i].label == data.label) {
                    basic[i].value.push(data)
                }
            }

            return {
                code: 20000,
                data: basic
            }

        }
    },
    // delBasic
    {
        url: '/vue-admin-template/basic/delDict',
        type: 'post',
        response: config => {
            let data = config.body
            for (let i = 0; i < basic.length; i++) {
                if (basic[i].label == data.label) {
                    basic.splice(i, 1)

                    return {
                        code: 20000,
                        data: basic
                    }
                }
            }


        }
    },
    // delOneBasic
    {
        url: '/vue-admin-template/basic/delOneDict',
        type: 'post',
        response: config => {
            let data = config.body
            let arr = []
            for (let i = 0; i < basic.length; i++) {
                if (basic[i].label == data.label) {
                    arr = basic[i].value
                    for (let j = 0; j < arr.length; j++) {
                        if (arr[j].id == data.id) {
                            arr.splice(j, 1)
                            basic[i].value = arr
                            return {
                                code: 20000,
                                data: basic
                            }
                        }
                    }
                }
            }
            return {
                code: 20000,
                data: basic
            }

        }
    },
    // editBasic
    {
        url: '/vue-admin-template/basic/editDict',
        type: 'post',
        response: config => {
            let data = config.body
            let arr = []
            for (let i = 0; i < basic.length; i++) {
                if (basic[i].label == data.label) {
                    arr = basic[i].value
                    for (let j = 0; j < arr.length; j++) {
                        if (arr[j].id == data.id) {
                            basic[i].value[j] = data
                            return {
                                code: 20000,
                                data: basic
                            }
                        }
                    }
                }
            }





        }
    },
]